package com.jason.exp.main;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
import java.util.Set;

/**
 * Created by fuyongde on 2016/9/27.
 */
@SupportedAnnotationTypes("com.jason.exp.main.FruitName")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class FruitNameProcessor extends AbstractProcessor {



    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        for (Element elem : roundEnv.getElementsAnnotatedWith(FruitName.class)) {
            FruitName complexity = elem.getAnnotation(FruitName.class);
            String message = "annotation found in " + elem.getSimpleName() + " with complexity " + complexity.value();
            System.out.println(message);
            processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, message);
            return true; // no further processing of this annotation type
        }
        return false;
    }
}
